package com.bluedot.www.core.pojo.BO;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.bluedot.www.core.common.excel.DateConverter;
import com.bluedot.www.core.pojo.DO.Log;
import com.bluedot.www.core.utils.IpUtil;

import java.io.Serializable;
import java.sql.Timestamp;

/**
 * <p>
 * 日志表excel
 * </p>
 *
 * @author Deng HongWei
 * @since 2021-08-07
 */
public class ExcelLog implements Serializable {

    @ExcelIgnore
    private static final long serialVersionUID = 1L;

    /**
     * 日志编号
     */
    @ExcelProperty(value = "日志编号")
    private Long id;

    /**
     * 用户编号
     */
    @ExcelProperty(value = "用户编号")
    private Long userId;

    /**
     * ip地址，建议使用无符号int类型
     */
    @ExcelProperty(value = "ip地址")
    private String ipAddress;

    /**
     * url，截取中间的URL
     */
    @ExcelProperty(value = "访问url")
    private String url;

    /**
     * 响应时间
     */
    @ExcelProperty(value = "响应时间")
    private Integer responseTime;

    /**
     * Http状态码
     */
    @ExcelProperty(value = "Http状态码")
    private String statusCode;

    /**
     * 账户名
     */
    @ExcelProperty(value = "账户名")
    private String account;

    /**
     * 创建时间
     */
    @ExcelProperty(value = "创建时间", converter = DateConverter.class)
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    private Timestamp gmtCreate;

    /**
     * 修改时间
     */
    @ExcelProperty(value = "修改时间", converter = DateConverter.class)
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    private Timestamp gmtModified;


    public ExcelLog(Log log) {
        this.id = log.getId();
        this.userId = log.getUserId();
        this.ipAddress = IpUtil.intToIpv4(log.getIpAddress());
        this.url = log.getUrl();
        this.responseTime = log.getResponseTime();
        this.statusCode = log.getStatusCode();
        this.account = log.getAccount();
        this.gmtCreate = log.getGmtCreate();
        this.gmtModified = log.getGmtModified();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Integer getResponseTime() {
        return responseTime;
    }

    public void setResponseTime(Integer responseTime) {
        this.responseTime = responseTime;
    }

    public String getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(String statusCode) {
        this.statusCode = statusCode;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public Timestamp getGmtCreate() {
        return gmtCreate;
    }

    public void setGmtCreate(Timestamp gmtCreate) {
        this.gmtCreate = gmtCreate;
    }

    public Timestamp getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(Timestamp gmtModified) {
        this.gmtModified = gmtModified;
    }

    @Override
    public String toString() {
        return "Log{" +
                "id=" + id +
                ", userId=" + userId +
                ", ipAddress=" + ipAddress +
                ", url=" + url +
                ", responseTime=" + responseTime +
                ", statusCode=" + statusCode +
                ", account=" + account +
                ", gmtCreate=" + gmtCreate +
                ", gmtModified=" + gmtModified +
                "}";
    }
}
